package cn.wolf.netty.protocoltcp;



import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

/**
 * 自定义协议TCP- 初始化类
 */
public class MyClientInitializer extends ChannelInitializer<SocketChannel> {

    /**
     * 数据出栈编码
     *
     * @param ch 上下文对象
     * @throws Exception 异常
     */
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        //添加编码处理器 handler
        pipeline.addLast(new MyMessageEncoder());
        //添加解码处理器 handler
        pipeline.addLast(new MyMessageDecoder());
        //添加在定义业务处理器 handler
        pipeline.addLast(new MyClientHandler());
    }
}
